import { EntityModel } from '@midwayjs/orm';
import { Column, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import dayjs from 'dayjs';
import { UserEntity } from './user';

@EntityModel({
  name: 'group_user',
})
export class GroupUserEntity {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    comment: '主键id',
  })
  id: number;

  @Column({
    type: 'bigint',
    name: 'group_id',
    nullable: false, // 不能为null
    comment: '群id',
  })
  groupId: number;

  @Column({
    type: 'bigint',
    name: 'user_id',
    nullable: false, // 不能为null
    comment: '群成员用户id',
  })
  userId: number;

  @Column({
    type: 'varchar',
    nullable: false, // 不能为null
    default: '',
    comment: '用户成员备注',
  })
  note: string;

  @Column({
    type: 'varchar',
    nullable: false, // 不能为null
    default: dayjs().format('YYYY-MM-DD HH:mm:ss'), // 默认值
    comment: '加入时间时间',
  })
  time: string;

  @ManyToOne(type => UserEntity)
  @JoinColumn({
    name: 'user_id',
  })
  users: UserEntity;
}
